package com.tjsinfo.tjsoa.worklog.action;

import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.system.vo.TSystemUser;
import com.tjsinfo.tjsoa.system.vo.User;
import com.tjsinfo.tjsoa.worklog.bo.IWorkLogDefineBo;
import com.tjsinfo.tjsoa.worklog.vo.WorkLogDefine;
public class AddWorkLogFromAction extends Action{
	private IWorkLogDefineBo workLogDefineBo;
	
	
	


	public IWorkLogDefineBo getWorkLogDefineBo() {
		return workLogDefineBo;
	}


	public void setWorkLogDefineBo(IWorkLogDefineBo workLogDefineBo) {
		this.workLogDefineBo = workLogDefineBo;
	}


	/* (non-Javadoc)
	 * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("user");
		// TODO Auto-generated method stub
		try {
			String definename = "";
			String define = "";
			String type = request.getParameter("type");
			Integer number = Integer.parseInt(request.getParameter("number"));
			Integer year = Integer.parseInt(request.getParameter("year"));
			String time = request.getParameter("time");
			//WorkLogDefine workLogDefine = workLogDefineBo.selectDefineAndType(type, user.getUser_id());
			List list = workLogDefineBo.selectDefine(user.getUser_id());
			request.setAttribute("type", type);
			request.setAttribute("number", number);
			request.setAttribute("year", year);
			request.setAttribute("time", time);
			if (list.size() <= 0) {
				request.setAttribute("define", "");
				request.setAttribute("definename", "");
			} else {
				// request.setAttribute("define", workLogDefine.getTjsUser().getId().toString());
				if (list.size() >0) {
					for (Iterator iterator = list.iterator(); iterator
							.hasNext();) {
						TSystemUser	 planDefine = (TSystemUser)iterator.next();
						definename +=","+planDefine.getUserName();
						define ="";
						
					}
					request.setAttribute("definename", definename);
					request.setAttribute("define","");
				} else {
					request.setAttribute("definename", "");
				}
			}
			
			return mapping.findForward("ok");
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			
		}
		return mapping.findForward("error");
	}
	
}
